<%- include("header",{type:''}) %>
<div class="container">
    <form style="width:100%" method="post" class="form create">
        <div>
            <label>标题:</label>
            <input type="text" placeholder="请输入标题" name="title" value="<%- postsTitle %>">
        </div>
        <div>
            <label>内容:</label>
            <textarea name="content" id="textedit" cols="42" rows="10" placeholder="请输入内容" onblur="texteditClick()">
                <%= postsContent %>
            </textarea>
        </div>
        <div class="submit">发表</div>
    </form>
</div>
<script>
    function texteditClick(){
        let textString =   $('#textedit').text().replace(/(^\s*)|(\s*$)/g, "");
        $('#textedit').val(textString)
    }
    $('.submit').click(function () {
        if ($('input[name=title]').val().trim() == '') {
            fade('请输入标题')
        } else if ($('textarea').val().trim() == '') {
            fade('请输入博客内容')
        } else {
            $.ajax({
                url: " ",
                data: $('.form').serialize(),
                type: "POST",
                cache: false,
                dataType: 'json',
                success: function (msg) {
                    if (msg.code == 200) {
                        fade("修改成功")
                        setTimeout(function () {
                            window.location.href = '/posts'
                        }, 1000)
                    } else {
                        fade('修改成功')
                    }
                },
                error: function (e) {
                    console.log(e);
                    alert("异常")
                }

            })
        }
    })
</script>
<% include footer %>